package cn.tedu.api;
//测试 字符串的工具类
public class Test3_StringBuffer {
    public static void main(String[] args) {
        //把指定的字符串拼接10000次，并输出结果

//        StringBuffer s = new StringBuffer();
//        s.append("+");
//       method();
//       method2();
       method3();
    }
    public static void method3(){
            String s = "niubi";
            StringBuilder sb = new StringBuilder();
            long start = System.currentTimeMillis();
            for (int i = 0; i <2 ; i++) {
                sb.append(s);
            }
            System.out.println(sb.append(s));
            long end = System.currentTimeMillis();
            System.out.println(end-start);
    }
    public static void method2(){
        String s = "niubi";
        StringBuffer sb = new StringBuffer();
        long start = System.currentTimeMillis();
        for (int i = 0; i <2 ; i++) {
            sb.append(s);
        }
        System.out.println(sb.append(s));
        long end = System.currentTimeMillis();
        System.out.println(end-start);


    }
    public static void method(){
        String s = "sfds";
        String res = "";//定义变量，记录拼接结果
        long start = System.currentTimeMillis();
        for (int i = 0; i <100000 ; i++) {
            res=res+s;//通过+拼接字符串
        }
        long end = System.currentTimeMillis();
        System.out.println(end-start);
    }
}
